package com.xycake.controller.client;

import com.xycake.entity.User;
import com.xycake.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/goods")
    public Map<String,Object> xycakegoods(Integer id){
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("data", orderService.selectOrder(id));
        return map;
    }

    @RequestMapping("/orders")
    public Map<String,Object> xycakeOrders(HttpSession session){
        User u = (User) session.getAttribute("loginUser");
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("data", orderService.selectAllById(u.getId()));
        return map;
    }

}
